interface RequestOptions {
  url: string
  method?: 'GET' | 'POST' | 'DELETE' | 'PUT'
  data?: object
}

const BaseUrl = 'https://zyxcl.xyz/music/api'
const request = <T = any>({
  url,
  method = 'GET',
  data = {}
}: RequestOptions) => {
  return new Promise<T>((resolve, reject) => {
    uni.request({
      url: BaseUrl + url, //仅为示例，并非真实接口地址。
      method,
      data,
      success: (res) => {
        resolve(res.data as T)
      },
      fail: e => {
        reject(e)
      },
      withCredentials:true
    })
  })
}

export default request